package com.nuoniu.sibanyun.service.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.entity.user.SysUserNote;
import com.nuoniu.sibanyun.mapper.user.SysUserNoteMapper;
import com.nuoniu.sibanyun.service.user.ISysUserNoteService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户便签、笔记 服务实现类
 * </p>
 *
 * @author baiqiang
 * @since 2020-09-03
 */
@Service
public class SysUserNoteServiceImpl extends ServiceImpl<SysUserNoteMapper, SysUserNote> implements ISysUserNoteService {

    @Override
    public Page<SysUserNote> pageList(Page pages, SysUserNote userNote) {
        UserInfo userInfo = UserThreadLocal.get();
        QueryWrapper<SysUserNote> queryWrapper = new QueryWrapper();
        queryWrapper.eq("type", userNote.getType());
        queryWrapper.eq("user_id", userInfo.getUserId());
        if(StringUtils.isNotBlank(userNote.getContentType())) {
            queryWrapper.eq("content_type", userNote.getContentType());
        }
        if(StringUtils.isNotBlank(userNote.getTitle())) {
            queryWrapper.like("title", userNote.getTitle());
        }
        queryWrapper.orderByDesc("create_date");
        Page page = page(pages, queryWrapper);
        return page;
    }
}
